#ifndef __LOG_H__
#define __LOG_H__

#include <base.h>
#include <Logger.h>

namespace mdk
{
    enum
    {
        /* output log's level */
        LOG_LVL_FATAL,
        LOG_LVL_ERROR,
        LOG_LVL_WARN,
        LOG_LVL_INFO,
        LOG_LVL_DEBUG,
        LOG_LVL_TRACE,
        LOG_LVL_NUM,
    };
#define MDK_CFG_PRINT_LOG 1
#ifdef __cplusplus
    extern "C"
    {
#endif
        extern void (*_func_logWrite)(int level, const char *file, const char *func,
                                      int line, const char *format, ...);

        void hexdump(const char *name, int width,
                     const unsigned char *buf, int size);

        void logWrite(int level, const char *file, const char *func,
                      int line, const char *format, ...);

#define LVOS_Log(level, format, ...)                                              \
    if (_func_logWrite == NULL)                                                   \
    {                                                                             \
        logWrite(level, __FILE__, __FUNCTION__, __LINE__, format, ##__VA_ARGS__); \
    }                                                                             \
    else                                                                          \
    {                                                                             \
        _func_logWrite(level, __FILE__, __FUNCTION__,                             \
                       __LINE__, format, ##__VA_ARGS__);                          \
    }
#define LOG_DBG(format, ...) \
    LVOS_Log(LOG_LVL_DEBUG, format, ##__VA_ARGS__)
#define LOG_INFO(format, ...) \
    LVOS_Log(LOG_LVL_INFO, format, ##__VA_ARGS__)
#define LOG_WARN(format, ...) \
    LVOS_Log(LOG_LVL_WARN, format, ##__VA_ARGS__)
#define LOG_ERROR(format, ...) \
    LVOS_Log(LOG_LVL_ERROR, format, ##__VA_ARGS__)
#define LOG_FATAL(format, ...) \
    LVOS_Log(LOG_LVL_FATAL, format, ##__VA_ARGS__)
#define LOG_TRACE(format, ...) \
    LVOS_Log(LOG_LVL_TRACE, format, ##__VA_ARGS__)
#define LVOS_DUMP(name, buf, siez) \
    hexdump(name, 16, (unsigned char *)buf, siez)

#ifdef __cplusplus
    }
#endif
}
#endif